﻿Imports MapleLib.PacketLib

Public Class ExtendedSPTable
    Public Enum Type
        EVAN
        RESISTANCE
    End Enum

    Public SPType As Type
    Public SPTable As Dictionary(Of Integer, Integer)
    Public BaseJob As Integer

    Sub New(ByVal jobid As Integer, ByVal sp As String)
        SPTable = New Dictionary(Of Integer, Integer)
        For i As Integer = 1 To 10
            SPTable.Add(i, CShort(sp.Split(",")(i)))
        Next
        'For i As Integer = 1 To 10
        'SPTable.Add(i, 0)
        'Next
        SPType = getTypeFromJobID(jobid)
        Select Case SPType
            Case Type.EVAN
                BaseJob = 2210
            Case Else
                BaseJob = 3000
        End Select
    End Sub

    Public Function getTypeFromJobID(ByVal jobid As Integer) As Type
        If jobid = 2001 Or Math.Floor(jobid / 100) = 22 Then
            Return Type.EVAN
        End If
        If Math.Floor(jobid / 1000) = 3 Then
            Return Type.RESISTANCE
        End If
        Return Nothing
    End Function

    Public Function getNonZeroSize() As Byte
        Dim ret As Byte = 0
        For Each i As Integer In SPTable.Values
            If i > 0 Then
                ret += 1
            End If
        Next
        Return ret
    End Function

    Public Sub addSPData(ByVal writer As PacketWriter)
        writer.WriteByte(getNonZeroSize())
        For i As Integer = 1 To SPTable.Count
            If SPTable.Values(i) > 0 Then
                writer.WriteByte(i)
                writer.WriteByte(SPTable.Values(i))
            End If
        Next
    End Sub
End Class